////////////////////////////////////////////////////////////////////////////////
//
//  MICROSOFT CORPORATION
//  Copyright (c) Microsoft Corporation.
//  All Rights Reserved.
//
//  NOTICE: Microsoft Confidential. Intended for Internal Use Only.
//
////////////////////////////////////////////////////////////////////////////////

package com.msn.beet.loaders
{

import com.msn.beet.errors.ArgumentOutOfRangeException;

import flash.utils.getQualifiedClassName;

/**
 * Abstract Base Class which handles the list operations for composite
 * AbstractLoaders
 *
 * @see AbstractLoader
 *
 */
public class AbstractLoaderComposite extends AbstractLoader
{
    include "../core/Version.as";

    public var _name:String;

    protected var loadQueue:LoaderCollection = new LoaderCollection();
    protected var isRunning:Boolean = false;
    protected var isLoading:Boolean = false;

    public static const IDLE:Boolean = false;
    public static const RUNNING:Boolean = true;

    /**
     * @param self keeps class from being instantiated
     */
    public function AbstractLoaderComposite(self:AbstractLoaderComposite)
    {
        super(this);

        if (self != this)
        {
            throw new ArgumentError(getQualifiedClassName(this) +
                                    " cannot be instantiated.");
        }
    }

    /**
     * Returns the number of loaders in the list
     *
     * @return
     */
    public function get length():uint
    {
        return this.loadQueue.count;
    }

    /**
     * Add AbstractLoader to list
     *
     * @param item
     */
    override public function add(loader:AbstractLoader):void
    {
        this.loadQueue.add(loader);
    }

    /**
     * Removes loader from list
     *
     * @param loader
     */
    override public function remove(loader:AbstractLoader):void
    {
        this.loadQueue.remove(loader);
    }

    /**
     * Clears list
     */
    public function reset():void
    {
        this.loadQueue.clear();
    }

    /**
     * Returns the AbstractLoader at the index passed in
     *
     * @param index
     * @return
     */
    override public function getChild(index:int):AbstractLoader
    {
        return AbstractLoader(this.loadQueue.getItem(index));
    }

    /**
     * Inserts loader in the list at the specified index
     *
     * @param loader
     * @param index
     */
    override public function insert(loader:AbstractLoader, index:int):void
    {
        this.loadQueue.insert(index, loader);
    }

}

}
